//
//  AccountCenterViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-6-23.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "AccountCenterViewController.h"
#import "AccountCenterTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "HZAreaPickerView.h"
#import "UpYun.h"

#import "ShopGuideCenterTableViewCell.h"
#import "MyFavoriteTableViewCell.h"
#import "CameraViewController.h"
#import "AddGuideViewController.h"
#import "GuideDetailViewController.h"
#import "AboutUSViewController.h"
#import "InfoFeedBackViewController.h"
#import "PasswordSetViewController.h"

@interface AccountCenterViewController ()<HZAreaPickerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIAlertViewDelegate,cameraDelegate,AddGuideDelegate,PasswordSetDelegate>
{
    CameraViewController *cameraVC;
    AddGuideViewController *addGuideVC;
    GuideDetailViewController *guideDetailVC;
    AboutUSViewController *aboutUSVC;
    InfoFeedBackViewController *infoFeedBackVC;
    PasswordSetViewController *passwordSetVC;
   
    NSArray *leftTableImageArray;
    NSArray *leftTableTitlArray;
    
    NSMutableArray *upYunImageArray;
      //myGuideView
    NSMutableArray *myGuideCodeArray;
    NSMutableArray *myGuideNameArray;
    NSMutableArray *myGuidePhoneArray;
    NSMutableArray *myGuideSexArray;
   
    NSMutableArray *myGuideStoreNameArray;
    NSMutableArray *myGuideAddressArray;
    NSString *qrCodeStr;
    
    NSString *analysisTypeStr;
    BOOL webIsOpen;
    NSString *timeTypeStr;
    
    NSString *policyStr;
    NSString *signatureStr;
    NSString *downLoadUrlStr;
    
    UIImage *img;


}
@property (strong, nonatomic) NSString *areaValue, *cityValue;
@property (strong, nonatomic) HZAreaPickerView *locatePicker;
@end

@implementation AccountCenterViewController
@synthesize areaValue=_areaValue, cityValue=_cityValue;
@synthesize locatePicker=_locatePicker;

-(void)viewWillAppear:(BOOL)animated
{
   if ([_isLoad isEqualToString:@"N"]) {
      downLoadUrlStr=@"";
      policyStr=@"";
      signatureStr=@"";
   
      if (cameraVC.view!=nil) {
          [cameraVC.view removeFromSuperview];
          [cameraVC removeFromParentViewController];
          
      }
      if (addGuideVC.view!=nil) {
           [addGuideVC.view removeFromSuperview];
           [addGuideVC removeFromParentViewController];

       }
       
       if (guideDetailVC.view!=nil) {
           [guideDetailVC.view removeFromSuperview];
           [guideDetailVC removeFromParentViewController];
           
       }
       if (aboutUSVC.view!=nil) {
           [aboutUSVC.view removeFromSuperview];
           [aboutUSVC removeFromParentViewController];
           
       }
       if (infoFeedBackVC.view!=nil) {
           [infoFeedBackVC.view removeFromSuperview];
           [infoFeedBackVC removeFromParentViewController];

       }
       
       if (passwordSetVC.view!=nil) {
           [passwordSetVC.view removeFromSuperview];
           [passwordSetVC removeFromParentViewController];
           
       }


    [self initViews];
    [self initMyGuideView];
    [self initSystemSetView];
    [self initMyAchieveView];
   
    leftTableImageArray=[NSArray arrayWithObjects:@"womendemendian_.png",@"womendedaogou_.png",@"wodeyeji_.png",@"xitongshezhi_.png",nil];
    leftTableTitlArray=[NSArray arrayWithObjects:@"我的门店",@"我的导购",@"门店业绩",@"系统设置",nil];
    _accountHeadIcon.layer.borderColor=[[UIColor colorWithRed:197.0f/255.0f green:163.0f/255.0f blue:89.0f/255.0f alpha:1] CGColor];
    _accountHeadIcon.layer.borderWidth= 3.0f;
    _accountHeadIcon.layer.cornerRadius=39;
     _accountHeadIcon.layer.masksToBounds = YES;
      
      _accountHeadIcon.userInteractionEnabled = YES;
      UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonpress1)];
      [_accountHeadIcon addGestureRecognizer:singleTap1];
      singleTap1=nil;
      

    [_leftTableView setBackgroundColor:[UIColor clearColor]];
         
         for (int i=0; i<5; i++) {
             
             NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:i inSection:0];
             UITableViewCell *cell = [_leftTableView cellForRowAtIndexPath:indexPath1];
             AccountCenterTableViewCell *accountCenterCell=( AccountCenterTableViewCell *)cell;
             accountCenterCell.lineLabel.hidden=NO;
             
                           
             
         }
      
    
       if ([[Global getLoginToken] length]>0) {
             NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0];
             [_leftTableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom];
             _systemSetViewContainer.hidden=YES;
             _myGuideViewContainer.hidden=YES;
             [_accountDetailViewContainer setContentOffset:CGPointMake(0, 0)];
             _accountDetailViewContainer.hidden=NO;
             _myAchieveViewContainer.hidden=YES;
             [_accountDetailViewContainer setShowsVerticalScrollIndicator:NO];
             [_accountDetailViewContainer setScrollEnabled:YES];
             // _detailViewContainer.hidden=YES;
             // _aboutUSViewContainer.hidden=YES;
             // _infoFeedbackViewContainer.hidden=YES;
        
       _accountStoreName.text=[Global getStoreName];
         // _accountStoreName.text=_storeNameLabel.text;
      
        int  labelHeight = [_accountStoreName getAttributedStringHeightWidthValue:190];
         
        _accountStoreName.frame = CGRectMake(_accountStoreName.frame.origin.x, _accountStoreName.frame.origin.y, 190.f, labelHeight);
        [_accountBtn setBackgroundColor:[UIColor colorWithRed:184.0f/255.0f green:136.0f/255.0f blue:45.0f/255.0f alpha:1.0f]];
     
        _accountGuideName.text=[Global getLoginGuideName];
        [self resizeLabel:_accountGuideName];
         [ _accountHeadIcon setImageWithURL:[NSURL URLWithString:[Global getHeadIconStr]]];
        CGRect frameT=_accountGuideNameTag.frame;
        frameT.origin.x=_accountGuideName.frame.origin.x+_accountGuideName.frame.size.width+2;
        _accountGuideNameTag.frame=frameT;
             
        [self requestStoreDetail:[Global getLoginToken]];

        }
  }
    
   

}
-(void)initMyAchieveView
{
    webIsOpen=NO;
    _typeView.hidden=YES;
    
    CGRect frame=_typeView.frame;
        
    frame.size.height=1;
    [_typeView setFrame:frame];
    
    _customView.hidden=YES;
    _runView.hidden=NO;
     analysisTypeStr=@"B";
    timeTypeStr=@"Today";
    _webTypeLabel.text=@"经营概况";
    
    _runTodayLineLabel.hidden=NO;
    _runWeekLineLabel.hidden=YES;
    _runMonthLineLabel.hidden=YES;
    _runLastMonthLineLabel.hidden=YES;
    
    CGRect webFrame=_myAchieveWebView.frame;
    webFrame.origin.y=92;
    webFrame.size.height=605;
    _myAchieveWebView.frame=webFrame;
//    CGRect webFrame=_myAchieveWebView.frame;
//    webFrame.origin.y=46;
//    _myAchieveWebView.frame=webFrame;
   
    _myAchieveViewContainer.hidden=YES;
    [_selectWebTypeButton addTarget:self action:@selector(selectWebType:) forControlEvents:UIControlEventTouchUpInside];

    [_customAnalysisButton addTarget:self action:@selector(selectWebContent:) forControlEvents:UIControlEventTouchUpInside];
    [_customRunAnalysisButton addTarget:self action:@selector(selectWebContent:) forControlEvents:UIControlEventTouchUpInside];
    [_runTodayButton addTarget:self action:@selector(selectWebContent:) forControlEvents:UIControlEventTouchUpInside];
    [_runWeekButton addTarget:self action:@selector(selectWebContent:) forControlEvents:UIControlEventTouchUpInside];
    [_runMonthButton addTarget:self action:@selector(selectWebContent:) forControlEvents:UIControlEventTouchUpInside];
    [_runLastMonthButton addTarget:self action:@selector(selectWebContent:) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)initSystemSetView
{
     _systemSetViewContainer.hidden=YES;
    [_passwordButton addTarget:self action:@selector(systemBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_feedbackButton addTarget:self action:@selector(systemBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_aboutUSButton addTarget:self action:@selector(systemBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)initMyGuideView
{
    _addGuideBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _addGuideBtn.layer.borderWidth= 1.0f;
    _addGuideBtn.layer.cornerRadius=3;
    [_addGuideBtn addTarget:self action:@selector(addShopGuideClick) forControlEvents:UIControlEventTouchUpInside];
    myGuideCodeArray=[NSMutableArray array];
    myGuideNameArray=[NSMutableArray array];
    myGuidePhoneArray=[NSMutableArray array];
    myGuideSexArray=[NSMutableArray array];
    myGuideStoreNameArray=[NSMutableArray array];
    myGuideAddressArray=[NSMutableArray array];
    _myGuideViewContainer.hidden=YES;

}
-(void)initViews
{
    for (int i=0; i<5; i++) {
        
        NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:i inSection:0];
        UITableViewCell *cell = [_leftTableView cellForRowAtIndexPath:indexPath1];
        AccountCenterTableViewCell *accountCenterCell=( AccountCenterTableViewCell *)cell;
        accountCenterCell.selected=NO;
    }
       // _userNameTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
    _quitButton.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _quitButton.layer.borderWidth= 1.0f;
    _quitButton.layer.cornerRadius=4;
    if (_barCodeTimer!=nil) {
        [_barCodeTimer invalidate];
        _barCodeTimer=nil;
    }

    qrCodeStr=@"";
    [_barCodeBtn addTarget:self action:@selector(barCodeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    _scanViewContainer.hidden=YES;
    if ([Global getLoginToken].length>0) {
      
        _accountDetailViewContainer.hidden=YES;
        _accountLineLabel.hidden=YES;
       // _detailViewContainer.hidden=NO;
    }
   else
   {
       for (UIView *v in _accountDetailViewContainer.subviews) {
           if (v.tag==9) {
               
               [v removeFromSuperview];
           }
           
       }

       [_accountHeadIcon setImage:[UIImage imageNamed:@"zhanghu_.png"]];
       _accountGuideName.text=@"未登录";
       _accountGuideNameTag.hidden=YES;
       [_accountBtn setBackgroundColor:[UIColor whiteColor]];
       _accountLineLabel.hidden=NO;
       
       _accountDetailViewContainer.hidden=YES;
       //_detailViewContainer.hidden=YES;
   }
 

}
-(void)buttonpress1
{
    _isLoad=@"Y";
    if (cameraVC.view!=nil) {
        [cameraVC.view removeFromSuperview];
        [cameraVC removeFromParentViewController];
        
    }
    cameraVC=[[CameraViewController alloc] init];
   cameraVC.delegate=self;
  
    
    
    cameraVC.view.frame = CGRectMake(0,
                                            0,
                                            self.view.bounds.size.width,
                                            self.view.bounds.size.height);
    
    [self addChildViewController:cameraVC];
    [self.view addSubview:cameraVC.view];

}
-(void)returnImg:(UIImage *) cameraImage
{
    img=cameraImage;
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:@"User" forKey:@"uploadType"];
        
        [HttpRequest requestLoginData:@"System/GetFormParams" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [Global setUpYunUrl:[severDataDict.dataDict objectForKey:@"action"]];
                    signatureStr=[severDataDict.dataDict objectForKey:@"signature"];
                    policyStr=[severDataDict.dataDict objectForKey:@"policy"];
                    
                    [Global setSignatureStr:signatureStr];
                    [Global setPolicyStr:policyStr];
                    //
                    downLoadUrlStr=[severDataDict.dataDict objectForKey:@"ImageZone"];
                    
                    [self upHeadIconToUpYun];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                        //  [Global loginViewController:self];
                    }
                    
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
    }
    

}

-(void)upHeadIconToUpYun
{
    
    __block NSInteger count=0;
    UpYun *uy = [[UpYun alloc] init];
    uy.successBlocker = ^(id data)
    {
        //  NSLog(@"zuzhijigouDATA======%@",data );
        count++;
        // NSLog(@"count======%d",count );
        // NSLog(@"_pictureView.subviews.count======%d",_pictureView.subviews.count );
        [Global hideProgressHUDInternal:self.view];
        NSString *imageStr;
        
        imageStr=[data objectForKey:@"url"];
        NSString *imgUrl=[NSString stringWithFormat:@"/%@",imageStr];
        
        if ([Global getLoginToken].length!=0&& imgUrl.length>0) {
            [Global showIndeterminateHudSub:@"上传中，请稍后。。。" delay:30 view:self.view];
            
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            
            [params setObject:imgUrl forKey:@"ImageUrl"];
            
            [HttpRequest requestData:@"System/UpLoadMyImage" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                // NSLog(@"uploadSever===%@",severDataDict.dataDict);
                // NSLog(@"uploadSeverRESULTSTR===%@",severDataDict.resultStr);
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        
                        [Global showTextHudSub:requestResultStr view:self.view];
                       // NSLog(@"touxiang====%@",severDataDict.dataDict);
                         NSString *imgStr=[NSString stringWithFormat:@"%@%@",downLoadUrlStr,imgUrl];
                         [ _accountHeadIcon setImageWithURL:[NSURL URLWithString:imgStr]];
                        
                        [Global setHeadIcon:imgStr];
                    }
                    else
                    {
                        
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        // [_uploadBtn setTitle:@"上传失败" forState:UIControlStateNormal];
                        // [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                            [Global loginViewController:self noteStr:requestResultStr];
                            //  [Global loginViewController:self];
                        }
                        
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    //  [_uploadBtn setTitle:@"上传失败" forState:UIControlStateNormal];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
        }
        
        
        
        
    };
    uy.failBlocker = ^(NSError * error)
    {
        [Global hideProgressHUDInternal:self.view];
         [Global showTextHudSub:@"上传失败" view:self.view];
//        NSString *message = [error.userInfo objectForKey:@"message"];
//        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"error" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
//        [alert show];
        //  NSLog(@"%@",error);
    };
    uy.progressBlocker = ^(CGFloat percent, long long requestDidSendBytes)
    {
        // [_pv setProgress:0.3333333333+percent/3];
    };
    // NSLog(@"selectePictureArray===%@",selectePictureArray);
    //for (int i=0; i<selectePictureArray.count; i++) {
    // UIImageView *imageview=(UIImageView *)[selectePictureArray  objectAtIndex:i];
    
    if (img!=nil) {
        UIImage *upImage=[self imageCompress:img];
        
        [Global showIndeterminateHudSub:@"正上传UPYUN，请稍后。。。" delay:120 view:self.view];
        uy.bucket=@"";
        [uy uploadFile:upImage saveKey:[self getSaveKey]];
        
    }
    //    }
    
    
}

-(void)barCodeBtnClick
{
    _scanViewContainer.hidden=NO;
    [self requestBarCodeImage];
    
}
-(void)requestBarCodeImage
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestBarCodeData:@"Common/CreateWxQrCode" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            [Global hideProgressHUDInternal:self.view];
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    //   NSLog(@"severdatdddddd111=%@",severDataDict.dataDict);
                    [_barcodeImageView setImageWithURL:[NSURL URLWithString:[severDataDict.dataDict objectForKey:@"QrCodeUrl"]]];
                    qrCodeStr=[severDataDict.dataDict objectForKey:@"QrCode"];
                    
                    _barCodeTimer = [NSTimer scheduledTimerWithTimeInterval:3.5 target:self selector:@selector(requestBarCodeInfo) userInfo:nil repeats:YES];
                    
                }
                else
                {
                   
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
//                    UIViewController *controller=[[GlobalViewController alloc]init];
//                    [self.navigationController pushViewController:controller animated:YES];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_barCodeTimer!=nil) {
                            [_barCodeTimer invalidate];
                            _barCodeTimer=nil;
                        }
              [Global loginViewController:self noteStr:requestResultStr];
                        //     [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(void)requestBarCodeInfo
{
    
    if ([Global getLoginToken].length>0) {
        // [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:qrCodeStr forKey:@"QrCode"];
        [HttpRequest requestBarCodeData:@"Common/GetQrCodeInf" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (_barCodeTimer!=nil) {
                [_barCodeTimer invalidate];
                _barCodeTimer=nil;
            }
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    //  [Global hideProgressHUDInternal:self.view];
                    
                    //
                    if ([[severDataDict.dataDict objectForKey:@"Subscribe"] integerValue]==0) {
                        // NSLog(@"rrrrrrrrrrr");
                        _scanViewContainer.hidden=YES;
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                  
//                    UIViewController *controller=[[GlobalViewController alloc]init];
//                    [self.navigationController pushViewController:controller animated:YES];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_barCodeTimer!=nil) {
                            [_barCodeTimer invalidate];
                            _barCodeTimer=nil;
                        }
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(IBAction)scanCancelBtnClick:(id)sender
{
    // [self stopReading];
    if (_barCodeTimer!=nil) {
        [_barCodeTimer invalidate];
        _barCodeTimer=nil;
    }
    //  timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(autoScrollCarousel) userInfo:nil repeats:YES];
    //    _priceTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(setLabelBackgroundAndAdv) userInfo:nil repeats:YES];
    //    [HttpRequest cancelRequest];
    
    _scanViewContainer.hidden=YES;
}
-(IBAction)selectTypeBtnCLick:(UIButton *)sender
{
    [_myAchieveViewContainer setContentOffset:CGPointMake(0, 0)];
    _typeView.hidden=YES;
    [UIView animateWithDuration:0.2 animations:^{
        CGRect frame=_typeView.frame;
        
        frame.size.height=1;
        [_typeView setFrame:frame];
        
    } completion:^(BOOL finished){
        webIsOpen=NO;
    }];
    
    if (sender.tag==100) {
         analysisTypeStr=@"A";
        _webTypeLabel.text=@"会员分析";
        _customView.hidden=YES;
        _runView.hidden=YES;
        CGRect webFrame=_myAchieveWebView.frame;
        webFrame.origin.y=46;
        webFrame.size.height=651;
        _myAchieveWebView.frame=webFrame;
    }
    if (sender.tag==101) {
        _webTypeLabel.text=@"经营概况";
        _runView.hidden=NO;
        _customView.hidden=YES;
        analysisTypeStr=@"B";
        timeTypeStr=@"Today";
        _runTodayLineLabel.hidden=NO;
        _runWeekLineLabel.hidden=YES;
        _runMonthLineLabel.hidden=YES;
        _runLastMonthLineLabel.hidden=YES;
        CGRect webFrame=_myAchieveWebView.frame;
        webFrame.origin.y=92;
          webFrame.size.height=605;
        _myAchieveWebView.frame=webFrame;
        
    }
    if (sender.tag==102) {
        _webTypeLabel.text=@"客流分析";
        timeTypeStr=@"";
         analysisTypeStr=@"C";
        _runView.hidden=YES;
        _customView.hidden=NO;
        _customAnalysisLineLabel.hidden=NO;
        _customRunAnalysisLineLabel.hidden=YES;
        CGRect webFrame=_myAchieveWebView.frame;
        webFrame.origin.y=92;
          webFrame.size.height=605;
        _myAchieveWebView.frame=webFrame;
    }
    [Global hideTextHudSub];
    [self requestWeb];
}

-(void)selectWebContent:(UIButton *)sender
{
    [_myAchieveViewContainer setContentOffset:CGPointMake(0, 0)];
    if (sender.tag==200)
    {
        analysisTypeStr=@"C";
        _customAnalysisLineLabel.hidden=NO;
        _customRunAnalysisLineLabel.hidden=YES;
    }
    if (sender.tag==201)
    {
        analysisTypeStr=@"D";
        _customAnalysisLineLabel.hidden=YES;
        _customRunAnalysisLineLabel.hidden=NO;
    }
    if (sender.tag==300)
    {
        timeTypeStr=@"Today";
        _runTodayLineLabel.hidden=NO;
        _runWeekLineLabel.hidden=YES;
        _runMonthLineLabel.hidden=YES;
        _runLastMonthLineLabel.hidden=YES;
    }
    if (sender.tag==301)
    {
        timeTypeStr=@"Week";
        _runTodayLineLabel.hidden=YES;
        _runWeekLineLabel.hidden=NO;
        _runMonthLineLabel.hidden=YES;
        _runLastMonthLineLabel.hidden=YES;
    }
    if (sender.tag==302)
    {
         timeTypeStr=@"Month";
        _runTodayLineLabel.hidden=YES;
        _runWeekLineLabel.hidden=YES;
        _runMonthLineLabel.hidden=NO;
        _runLastMonthLineLabel.hidden=YES;
    }
    if (sender.tag==303)
    {
        timeTypeStr=@"Defined";
        _runTodayLineLabel.hidden=YES;
        _runWeekLineLabel.hidden=YES;
        _runMonthLineLabel.hidden=YES;
        _runLastMonthLineLabel.hidden=NO;

    }
    [Global hideTextHudSub];
    [self requestWeb];
        
}
-(void)requestWeb
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:analysisTypeStr forKey:@"AnalysisType"];
        [params setObject:timeTypeStr forKey:@"TimeType"];
        
        [HttpRequest requestData:@"DataCenter/StoreAnalysis" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
              //  NSLog(@"severddd===%@",severDataDict.dataDict);
                 [Global hideProgressHUDInternal:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *urlStr=[severDataDict.dataDict objectForKey:@"AnalysisUrl"];
                   // [Global showTextHudSub:requestResultStr view:self.view];
                    NSURL *url = [[NSURL alloc]initWithString:urlStr];
                    // NSURL *url = [[NSURL alloc]initWithString:@" http://reabam.f3322.org:90/ZB_Web/charts/doc/example/theme.html"];
                   
                 // NSLog(@"url===%@",url);
                    [_myAchieveWebView loadRequest:[NSURLRequest requestWithURL:url]];
                    
                }
                else
                {
                    // NSLog(@"loginnnnnnnnn");
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        if (_barCodeTimer!=nil) {
                        [_barCodeTimer invalidate];
                         _barCodeTimer=nil;
                        }
                         [Global loginViewController:self noteStr:requestResultStr];
                        //[Global loginViewController:self];
                    }


//                    UIViewController *controller=[[GlobalViewController alloc]init];
//                    [self.navigationController pushViewController:controller animated:YES];
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
                
            }
        }];
        
    }

}
-(void)selectWebType:(UIButton *)sender
{
    if (webIsOpen) {
        _typeView.hidden=YES;
        [UIView animateWithDuration:0.2 animations:^{
            CGRect frame=_typeView.frame;
            
            frame.size.height=1;
            [_typeView setFrame:frame];
            
        } completion:^(BOOL finished){
            webIsOpen=NO;
        }];
        
    }
    
    else
    {
        _typeView.hidden=NO;
        [UIView animateWithDuration:0.2 animations:^{
            CGRect frame=_typeView.frame;
            
            frame.size.height=170;
            [_typeView setFrame:frame];
            
        } completion:^(BOOL finished){
            webIsOpen=YES;
        }];

    }

}

-(void)systemBtnClick:(UIButton *)sender
{
    if (sender.tag==50) {
        if (passwordSetVC.view!=nil) {
            [passwordSetVC.view removeFromSuperview];
            [passwordSetVC removeFromParentViewController];
            
        }
        passwordSetVC=[[PasswordSetViewController alloc] init];
        passwordSetVC.delegate=self;
        passwordSetVC.view.frame = CGRectMake(0,
                                               0,
                                               self.view.bounds.size.width,
                                               self.view.bounds.size.height);
        
        [self addChildViewController:passwordSetVC];
        [self.view addSubview:passwordSetVC.view];

    }
   else if (sender.tag==51) {
       if (infoFeedBackVC.view!=nil) {
           [infoFeedBackVC.view removeFromSuperview];
           [infoFeedBackVC removeFromParentViewController];
           
       }
       infoFeedBackVC=[[InfoFeedBackViewController alloc] init];
       infoFeedBackVC.view.frame = CGRectMake(0,
                                         0,
                                         self.view.bounds.size.width,
                                         self.view.bounds.size.height);
       
       [self addChildViewController:infoFeedBackVC];
       [self.view addSubview:infoFeedBackVC.view];

       
    }
    else if (sender.tag==52) {
        if (aboutUSVC.view!=nil) {
            [aboutUSVC.view removeFromSuperview];
            [aboutUSVC removeFromParentViewController];
            
        }
        aboutUSVC=[[AboutUSViewController alloc] init];
        aboutUSVC.view.frame = CGRectMake(0,
                                           0,
                                           self.view.bounds.size.width,
                                           self.view.bounds.size.height);
        
        [self addChildViewController:aboutUSVC];
        [self.view addSubview:aboutUSVC.view];

    }
}
-(void)resetPasswordSuccess:(NSString *)resultStr
{
    if (passwordSetVC.view!=nil) {
        [passwordSetVC.view removeFromSuperview];
        [passwordSetVC removeFromParentViewController];
        
    }

      [Global showTextHudSub:resultStr view:self.view];
}
-(void)addShopGuideClick
{
    if (addGuideVC.view!=nil) {
        [addGuideVC.view removeFromSuperview];
        [addGuideVC removeFromParentViewController];
        
    }
    addGuideVC=[[AddGuideViewController alloc] init];
    addGuideVC.delegate=self;
    
    addGuideVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:addGuideVC];
    [self.view addSubview:addGuideVC.view];
    
}
-(void)saveGuideSuccess
{
    [self requestGuideList];
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;{
    // the user clicked OK
    if (alertView.tag==100) {
    
    if (buttonIndex == 0)
    {
        _myGuideViewContainer.hidden=YES;
        _systemSetViewContainer.hidden=YES;
        _myAchieveViewContainer.hidden=YES;
      
        for (int i=0; i<5; i++) {
            
            NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:i inSection:0];
            UITableViewCell *cell = [_leftTableView cellForRowAtIndexPath:indexPath1];
            AccountCenterTableViewCell *accountCenterCell=( AccountCenterTableViewCell *)cell;
            accountCenterCell.selected=NO;
        }


    }
    }
}
-(void)requestStoreDetail:(NSString *)tokenStr
{
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
    [params setObject:tokenStr forKey:@"Token"];
//    [params setObject:[Global md5:_passWordTextField.text] forKey:@"LoginWord"];
//    [params setObject:@"S" forKey:@"AppType"];
    //  NSLog(@"parr===%@",params);
    [HttpRequest requestData:@"ShopManager/GetStoreMsg" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
             // NSLog(@"severddd33333===%@",severDataDict.dataDict);
            // [Global hideProgressHUDInternal:self.view];
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
               // _detailViewContainer.hidden=NO;
                _accountDetailViewContainer.hidden=NO;
                if ([severDataDict.dataDict objectForKey:@"OpenTime"]!=[NSNull null]&&[severDataDict.dataDict objectForKey:@"OverTime"]!=[NSNull null]) {
                     _openTimeLabel.text=[NSString stringWithFormat:@"%@-%@",[severDataDict.dataDict objectForKey:@"OpenTime"],[severDataDict.dataDict objectForKey:@"OverTime"] ];
                }
                if ([severDataDict.dataDict objectForKey:@"Phone"]!=[NSNull null]) {
                    _storePhoneLabel.text=[severDataDict.dataDict objectForKey:@"Phone"];
                }
                if ([severDataDict.dataDict objectForKey:@"CompanyCode"]!=[NSNull null]) {
                    _companyCodeLabel.text=[severDataDict.dataDict objectForKey:@"CompanyCode"];
                }

                if ([severDataDict.dataDict objectForKey:@"CompanyName"]!=[NSNull null]) {
                    _companyNameLabel.text=[severDataDict.dataDict objectForKey:@"CompanyName"];
                }
                

                if ([severDataDict.dataDict objectForKey:@"CompanyImageUrl"]!=[NSNull null]&&[[severDataDict.dataDict objectForKey:@"CompanyImageUrl"] length]>0) {
                    [_companyLogoImage setImageWithURL:[NSURL URLWithString:[severDataDict.dataDict objectForKey:@"CompanyImageUrl"]]];
            
                }
                else
                {
                    [_companyLogoImage setImage:[UIImage imageNamed:@"tupianzhanweitu_.png"]];
                }
//                if ([severDataDict.dataDict objectForKey:@"RegTime"]!=[NSNull null]) {
//                _shopTimeLabel.text=[severDataDict.dataDict objectForKey:@"RegTime"];
//                }
                if ([severDataDict.dataDict objectForKey:@"Address"]!=[NSNull null])
                {
                _storeAddressLabel.text=[severDataDict.dataDict objectForKey:@"Address"];
                 }
                if ([severDataDict.dataDict objectForKey:@"StoreCode"]!=[NSNull null]&&[severDataDict.dataDict objectForKey:@"StoreName"]!=[NSNull null])
                {
                _storeNameLabel.text=[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"StoreName"]];
                      [Global setStoreName:_storeNameLabel.text];
                    

                }
                 [_accountDetailWebView setPaginationMode:UIWebPaginationModeTopToBottom];
                
                NSURL *url = [[NSURL alloc]initWithString:[severDataDict.dataDict objectForKey:@"StoreDespUrl"]];
              
                // NSURL *url = [[NSURL alloc]initWithString:@"http://reabam.f3322.org:90/ZB_Web/charts/doc/example/theme.html"];
                
                [_accountDetailWebView loadRequest:[NSURLRequest requestWithURL:url]];
                
                
               }
            else
            {
                // NSLog(@"loginnnnnnnnn");
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    if (_barCodeTimer!=nil) {
                        [_barCodeTimer invalidate];
                        _barCodeTimer=nil;
                    }
                    
                     [Global loginViewController:self noteStr:requestResultStr];
                    //[Global loginViewController:self];
                }

            }
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:@"连接失败" view:self.view];
            
        }
    }];
    

}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
   // [Global hideProgressHUDInternal:self.view];
    [Global showTextHudSub:@"网页加载失败" view:self.view];
   // NSLog(@"error load");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [Global hideTextHudSub];
   // [Global hideProgressHUDInternal:self.view];
    if (webView==_accountDetailWebView) {
        
        [self performSelector:@selector(getWebHeight) withObject:nil afterDelay:0.3];
     
    }
    else if (webView==_myAchieveWebView)
     [self performSelector:@selector(getAchieveWebViewHeight) withObject:nil afterDelay:0.3];
}
-(void)getAchieveWebViewHeight
{
    NSString *meta = [NSString stringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"", _myAchieveWebView.frame.size.width];
    [_myAchieveWebView stringByEvaluatingJavaScriptFromString:meta];
//
//    
//    CGSize actualSize = [_myAchieveWebView sizeThatFits:CGSizeZero];
//    CGRect newFrame = _myAchieveWebView.frame;
//    newFrame.size.height = actualSize.height;
//    _myAchieveWebView.frame = newFrame;
//    NSLog(@"heightttttt===%0.02f",newFrame.size.height);
////
//    [_myAchieveViewContainer setScrollEnabled:YES];
//    
//    [_myAchieveViewContainer setContentSize:CGSizeMake(0, _myAchieveWebView.frame.origin.y+_myAchieveWebView.frame.size.height)];
//    //  NSLog(@"frame gggg= %f",htmlHeight);
//    [_myAchieveViewContainer setShowsVerticalScrollIndicator:NO];
}
-(void)getWebHeight
{
    [_accountDetailWebView sizeToFit];
   CGFloat height = _accountDetailWebView.scrollView.contentSize.height;
       [_accountDetailViewContainer setContentSize:CGSizeMake(0, _accountDetailWebView.frame.origin.y+height+10)];
  //  NSLog(@"frame gggg= %f",htmlHeight);
    [_accountDetailViewContainer setShowsVerticalScrollIndicator:NO];
    [_accountDetailViewContainer setScrollEnabled:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView==_leftTableView) {
        
        return 4;
    }
    else if (tableView==_myGuideTableView)
        return myGuideCodeArray.count;
  
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_leftTableView) {
        
        return 70;
            }
    else if (tableView==_myGuideTableView) {
        
        return 120;
    }
        return 50;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_leftTableView) {
        
        static NSString * const  leftIdentifier = @"leftIdentifier";
        AccountCenterTableViewCell *cell=( AccountCenterTableViewCell *)[tableView dequeueReusableCellWithIdentifier: leftIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"AccountCenterTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height+1)  ] ;
        cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];
        cell.lineLabel.hidden=NO;
        //     NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:_selectID inSection:indexPath.section];
        //       // if (indexPath.row==0) {
        //            [tableView selectRowAtIndexPath:indexPath1 animated:NO scrollPosition:UITableViewScrollPositionNone];
        // }
        if (leftTableImageArray.count>0) {
            [ cell.titleImageView setImage:[UIImage imageNamed:[leftTableImageArray objectAtIndex:indexPath.row]]];
        }
        if (leftTableTitlArray.count>0) {
            cell.titleLabel.text=[leftTableTitlArray objectAtIndex:indexPath.row];
            }

        return cell;
    }
   else if (tableView==_myGuideTableView) {
        
        static NSString * const  myGuideTableViewIdentifier = @"myGuideTableView";
        ShopGuideCenterTableViewCell *cell=( ShopGuideCenterTableViewCell *)[tableView dequeueReusableCellWithIdentifier: myGuideTableViewIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ShopGuideCenterTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (myGuideNameArray.count>0&&myGuidePhoneArray.count>0) {
            cell.guideNameLabel.text=[NSString stringWithFormat:@"%@(%@)",[myGuideNameArray objectAtIndex:indexPath.row],[myGuidePhoneArray objectAtIndex:indexPath.row]];//[shopGuideNameArray objectAtIndex:indexPath.row];
            
            [self resizeLabel:cell.guideNameLabel];
            
        }
        if (myGuideSexArray.count>0) {
            if ([[myGuideSexArray objectAtIndex:indexPath.row] isEqualToString:@"女"]) {
                [cell.sexImageView setImage:[UIImage imageNamed:@"nv_.png"]];
            }
            else
            {
                [cell.sexImageView setImage:[UIImage imageNamed:@"nan_.png"]];
            }
            CGRect frame=cell.sexImageView.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+2;
            cell.sexImageView.frame=frame;
            
          }
       if (myGuideStoreNameArray.count>0) {
           cell.storeNameLabel
           .text=[myGuideStoreNameArray objectAtIndex:indexPath.row];
       }
       if (myGuideAddressArray.count>0) {
           cell.addresslabel
           .text=[myGuideAddressArray objectAtIndex:indexPath.row];
       }
       

        return cell;
    }

    return nil;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    for (int i=0; i<5; i++) {
        
        NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:i inSection:0];
        UITableViewCell *cell = [_leftTableView cellForRowAtIndexPath:indexPath1];
        AccountCenterTableViewCell *accountCenterCell=( AccountCenterTableViewCell *)cell;
        accountCenterCell.lineLabel.hidden=NO;
        if (indexPath.row!=0) {
            NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:indexPath.row-1 inSection:0];
            UITableViewCell *cell = [_leftTableView cellForRowAtIndexPath:indexPath1];
            AccountCenterTableViewCell *accountCenterCell=( AccountCenterTableViewCell *)cell;
            accountCenterCell.lineLabel.hidden=YES;
        }

    }

      // if ([Global getLoginToken].length>0) {
     //  [_requestAccountScrollView setContentOffset:CGPointMake(0, 0)];
    if (tableView==_leftTableView) {
        if(indexPath.row==0)
        {
            _systemSetViewContainer.hidden=YES;
            _myGuideViewContainer.hidden=YES;
             [_accountDetailViewContainer setContentOffset:CGPointMake(0, 0)];
            _accountDetailViewContainer.hidden=NO;
            
             _myAchieveViewContainer.hidden=YES;
           // _detailViewContainer.hidden=YES;
           // _aboutUSViewContainer.hidden=YES;
           // _infoFeedbackViewContainer.hidden=YES;
            
             [self requestStoreDetail:[Global getLoginToken]];

        }
        else if (indexPath.row==1)
        {
            _systemSetViewContainer.hidden=YES;
            _myGuideViewContainer.hidden=NO;
            
             _accountDetailViewContainer.hidden=YES;
             _myAchieveViewContainer.hidden=YES;
            [self requestGuideList];
        }
        else if (indexPath.row==2)
        {
            _systemSetViewContainer.hidden=YES;
            _accountDetailViewContainer.hidden=YES;
            _myGuideViewContainer.hidden=YES;
            
             _myAchieveViewContainer.hidden=NO;
            [_myAchieveViewContainer setContentOffset:CGPointMake(0, 0)];
            [Global hideTextHudSub];
            
            [self requestWeb];

           // _detailViewContainer.hidden=YES;
           // _aboutUSViewContainer.hidden=YES;
           
        }
        else if (indexPath.row==3)
        {

            _myGuideViewContainer.hidden=YES;
            _systemSetViewContainer.hidden=NO;
            _accountDetailViewContainer.hidden=YES;
           
             _myAchieveViewContainer.hidden=YES;

        }
    }
    else if (tableView==_myGuideTableView)
    {
        if (guideDetailVC.view!=nil) {
            [guideDetailVC.view removeFromSuperview];
            [guideDetailVC removeFromParentViewController];
            
        }
        guideDetailVC=[[GuideDetailViewController alloc] init];
        
        guideDetailVC.guideCodeString=[myGuideCodeArray objectAtIndex:indexPath.row];
        guideDetailVC.view.frame = CGRectMake(0,
                                           0,
                                           self.view.bounds.size.width,
                                           self.view.bounds.size.height);
        
        [self addChildViewController:guideDetailVC];
        [self.view addSubview:guideDetailVC.view];
        

  }
}

-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        
        [HttpRequest requestData:@"ShopManager/GetGuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                 //    NSLog(@"tt=%@",severDataDict.dataDict);
                    [Global hideProgressHUDInternal:self.view];
                    [myGuideCodeArray removeAllObjects];
                    [myGuideNameArray removeAllObjects];
                    [myGuidePhoneArray removeAllObjects];
                    [myGuideSexArray removeAllObjects];
                    [myGuideStoreNameArray removeAllObjects];
                    [myGuideAddressArray removeAllObjects];
                   
                    
                    NSMutableArray  *mGuidesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [myGuideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"GuideCode"]];
                        [myGuideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"GuideName"]];
                        [myGuideSexArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"Sex"]];
                        [myGuidePhoneArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"Phone"]];
                        
                        NSString *addressStr1=[NSString stringWithFormat:@"%@%@%@%@",[[mGuidesArray objectAtIndex:i] objectForKey:@"ProvinceName"],[[mGuidesArray objectAtIndex:i] objectForKey:@"CityName"],[[mGuidesArray objectAtIndex:i] objectForKey:@"RegionName"],[[mGuidesArray objectAtIndex:i] objectForKey:@"Address"]];
                        [myGuideAddressArray addObject:addressStr1];
                        [myGuideStoreNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"StoreName"]];
                    }
                    [_myGuideTableView reloadData];
//                    if (mGuidesArray.count>0) {
//                        NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0];
//                        [_shopGuideListTableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom];
//                        
//                        //   UITableViewCell *cell = [_leftTableView cellForRowAtIndexPath:ip];
//                        //  ProductCommonTableViewCell *hjCell=( ProductCommonTableViewCell *)cell;
//                        
//                        // hjCell.lineLabel.hidden=NO;
//                        guideCodeStr=[[mGuidesArray objectAtIndex:0] objectForKey:@"GuideCode"];
//                        //                        _PageIndex=0;
//                        //                        [self loadItemNextPage:_PageIndex];
//                        [self requestGuideDetail:guideCodeStr];
//                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_barCodeTimer!=nil) {
                            [_barCodeTimer invalidate];
                            _barCodeTimer=nil;
                        }
                         [Global loginViewController:self noteStr:requestResultStr];
                        
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}


-(NSString * )getSaveKey {
    NSDate *d = [NSDate date];
    int value = arc4random() % 1000;
    return [NSString stringWithFormat:@"/%d/%d/%d.jpg",[self getYear:d],[self getMonth:d],value];
}

- (int)getYear:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSYearCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int year=[comps year];
    return year;
}

- (int)getMonth:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSMonthCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int month = [comps month];
    return month;
}

-(UIImage *)imageCompress:(UIImage *)image
{
    UIImage *comImage=image;
    NSData * sendImageData = UIImageJPEGRepresentation(comImage, 1.0);
    NSUInteger sizeOrigin = [sendImageData length];
    NSUInteger sizeOriginKB = sizeOrigin / 1024;
    
    if (sizeOriginKB >200) {
        float a = 200.0000;
        float b = (float)sizeOriginKB;
        float q = sqrtf(a / b);
        
        CGSize sizeImage = [comImage size];
        CGFloat widthSmall = sizeImage.width * q;
        CGFloat heighSmall = sizeImage.height * q;
        CGSize sizeImageSmall = CGSizeMake(widthSmall, heighSmall);
        
        UIGraphicsBeginImageContext(sizeImageSmall);
        CGRect smallImageRect = CGRectMake(0, 0, sizeImageSmall.width, sizeImageSmall.height);
        [image drawInRect:smallImageRect];
        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        NSData *dataImage = UIImageJPEGRepresentation(smallImage, 1.0);
        sendImageData = dataImage;
        
        comImage= smallImage;
        // [_imageview1.image retain];
    }
    return comImage;
}
-(IBAction)quitButtonClick:(id)sender
{
    [Global loginViewController:self noteStr:@"已退出登录"];
}
-(void)resizeLabel:(UILabel *)aLabel
{
    aLabel.lineBreakMode =NSLineBreakByWordWrapping;
    aLabel.numberOfLines =0;
    
    NSString *contentStr=aLabel.text;
    //if (contentStr) {
    aLabel.autoresizesSubviews = YES;
    aLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    
    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:contentStr];
    aLabel.attributedText = attrStr;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    NSDictionary *attribute = @{NSFontAttributeName:aLabel.font, NSParagraphStyleAttributeName:paragraphStyle.copy};
    CGSize textSize = [aLabel.text boundingRectWithSize:CGSizeMake(1000,aLabel.frame.size.height) // 用于计算文本绘制时占据的矩形块
                                                options:NSStringDrawingUsesLineFragmentOrigin //| NSStringDrawingUsesFontLeading // 文本绘制时的附加选项
                                             attributes:attribute        // 文字的属性
                                                context:nil].size; // context上下文。包括一些信息，例如如何调整字间距以及缩放。该对象包含的信息将用于文本绘制。该参数可为nil
    CGRect frame = CGRectMake(aLabel.frame.origin.x, aLabel.frame.origin.y,textSize.width, aLabel.frame.size.height );
    aLabel.frame=frame;
    
    
    
}
- (double)GetStringTimeDiff:(NSString*)timeS timeE:(NSString*)timeE

{
    
    double timeDiff = 0.0;
    
    NSDateFormatter *formatters = [[NSDateFormatter alloc] init];
    [formatters setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *dateS = [formatters dateFromString:timeS];
    
    
    
    NSDateFormatter *formatterE = [[NSDateFormatter alloc] init];
    [formatterE setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *dateE = [formatterE dateFromString:timeE];
    
    
    timeDiff = [dateE timeIntervalSinceDate:dateS ];
    
    return timeDiff;
    
}

- (NSString*)GetCurTime

{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString*timeString=[formatter stringFromDate: [NSDate date]];
    
    
    return timeString;
}
- (BOOL)validateMobile:(NSString *)mobileNum
{
    /**
     * 手机号码
     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     * 联通：130,131,132,152,155,156,185,186
     * 电信：133,1349,153,180,189
     */
    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|7[678]|8[025-9])\\d{8}$";
    /**
     10         * 中国移动：China Mobile
     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     12         */
    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    /**
     15         * 中国联通：China Unicom
     16         * 130,131,132,152,155,156,185,186
     17         */
    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    /**
     20         * 中国电信：China Telecom
     21         * 133,1349,153,180,189
     22         */
    NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    
    NSString *others=@"^1((4[57]|7[0]))\\d{8}$";
    /**
     25         * 大陆地区固话及小灵通
     26         * 区号：010,020,021,022,023,024,025,027,028,029
     27         * 号码：七位或八位
     28         */
    // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    NSPredicate *regextestothers = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", others];
    
    if (([regextestmobile evaluateWithObject:mobileNum] == YES)
        || ([regextestcm evaluateWithObject:mobileNum] == YES)
        || ([regextestct evaluateWithObject:mobileNum] == YES)
        || ([regextestcu evaluateWithObject:mobileNum] == YES)||([regextestothers evaluateWithObject:mobileNum] == YES))
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
